import random
users= {}
rooms= {}
class user(object):
      def __init__(self,name,sex,blood):
         self.name = name
         self.sex = sex
         self.blood = blood
         self.room= None

      def Fight(self,rival):
         fight= {"防弹衣":5,"残破小刀":10,"无用大棒":20,"饮血剑":50}
         store = {1: "防弹衣", 2: "残破小刀", 3: "无用大棒", 4: "饮血剑"}
         if rival  == self :
          print("请珍惜自己的生命！")
         else:
          if self.room and self.room == rival.room:
                 if self.blood <= 0:
                    print("您已阵亡，别灰心，买好装备提升自己下次一定可以的！")
                 else:
                   # print(f"尊贵的玩家，您已拥有如下装备：\n{self.eq}\n")
                   # ceq = input("请输入要使用的装备序号来保证下场猎杀的胜利，输入”0“这次先放过他不使用装备\n")
                   print("接收命运的安排吧！")
                   ceq =random.choice([1,2,3,4])
                   if ceq==1:
                    lost_blood = 5
                    print(f"{rival.name}使用了防弹衣")
                   else:
                    print(f"{self.name}使用了{store[ceq]}装备")
                    lost_blood = fight[store[ceq]]
                   rival.blood = int(rival.blood) - int(lost_blood)
                   print(f"{self.name}攻击了{rival.name}   {lost_blood}点血量，{rival.name}当前血量 {rival.blood}")
                   if rival.blood <= 0:
                    print(f"{rival.name}已阵亡，不能再进行攻击")
                    exit()
          else:
             print("不在同一个房间不能攻击")
class Room(object):
  def __init__(self,name):
        self.name = name
        self.member_list =[]
  def add_member(self,user):
     if user.room == None:
      if len(self.member_list) < 2:
       self.member_list.append(user)
       user.room = self
       print(f"{user.name}成功加入{self.name}房间")
     else:
       print(f"{user.name}已加入{user.room.name}房间")







print("Welcome to our  game  !" )
print("请选择操作")
print("1.创建角色\n2.创建房间\n3.加入房间\n4.开始战斗\n5.退出\n")

while 1:
    choice= input("请输入您的操作：\n")
    if choice.isdigit():
      choice = int(choice)
      if 1 <= choice <= 5:
         if choice == 1:
           name,sex = input("请输入角色的姓名与性别，空格分隔：\n").split()
           # money =100   #每人默认100
           # eq={}
           # store ={1:"防弹衣",2:"小血瓶",3:"大血瓶",4:"复生丸"}
           # print("下面进行装备购买，温馨提示合理搭配才能祝您取胜哦！\n")
           # print("输入序号进行装备购买，按”0“退出购买！\n")
           # c =input("1.防弹衣 20金币 \n2.小血瓶 30金币\n 3.大血瓶 50金币 \n4.复生丸 80金币\n")
           # while money>=0 and c!=0:
           #      eq[c]=store[c]
           #      c = input("1.防弹衣 20金币 \n2.小血瓶 30金币\n 3.大血瓶 50金币 \n4.复生丸 80金币\n")
           # print("你的装备如下\n{eq}")
           users[name] = user(name,sex,100)
         elif choice == 2:
             room1 = input("请输入房间的名字：\n")
             rooms[room1] = Room(room1)
         elif choice == 3:
             print(f"现有角色{users.keys()}，现有房间{rooms.keys()}")
             user_n,room_n = input("请输入您要加入的角色和房间名，空格分隔:\n").split()
             rooms[room_n].add_member(users[user_n])
         elif choice == 4:
           while True:
            suiji = random.choice([0,1])
            if suiji == 0:
             rooms[room_n].member_list[0].Fight(rooms[room_n].member_list[1])
            else:
             rooms[room_n].member_list[1].Fight(rooms[room_n].member_list[0])
      else:
         print("输入错误！请输入1-5选择操作！")
    else:
        print("输入有误！请重新输入！")


